package com.atguigu.stream.service.impl;

import com.atguigu.stream.service.IMessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.messaging.Source;
import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.support.MessageBuilder;

import java.util.UUID;


@EnableBinding(Source.class) //定义消息发送通道
public class MessageServiceImpl implements IMessageService {

    @Autowired
    private MessageChannel output;

    @Override
    public String sendMsg() {
        String s = UUID.randomUUID().toString();
        output.send(MessageBuilder.withPayload(s).build());
        System.out.println("消息发送成功："+s);
        return s;
    }
}
